// class 挑战
type Title = "Engineer" | "Salesperson" | "Accountant" | "Legal Team Lead";

class BaseEmployee {
  id: number;
  name: string;
  salary: number;

  constructor(id: number, name: string, salary: number) {
    this.id = id;
    this.name = name;
    this.salary = salary;
  }
  getSalary(): number {
    return this.salary;
  }
}

class Employee extends BaseEmployee {
  title: Title;

  constructor(id: number, name: string, title: Title, salary: number) {
    super(id, name, salary);
    this.title = title;
  }

  changeTitle(newTitle: Title): void {
    this.title = newTitle;
  }
}

class Manager extends BaseEmployee {
  title: string;
  directReports: Employee[];

  constructor(
    id: number,
    name: string,
    title: string,
    salary: number,
    directReports: Employee[]
  ) {
    super(id, name, salary);
    this.title = title;
    this.directReports = directReports;
  }

  addDirectReport(employee: Employee): void {
    this.directReports.push(employee);
  }

  removeDirectReport(employee: Employee): void {
    this.directReports = this.directReports.filter((i) => i.id !== employee.id);
  }
}

const charile = new Employee(1, "Charlie", "Engineer", 90_000);
const managerAlice = new Manager(1, "Alice", "Manager", 120_000, [charile]);

console.log(managerAlice.directReports);
managerAlice.removeDirectReport(charile);
console.log(managerAlice.directReports);

managerAlice.addDirectReport(charile);
charile.changeTitle("Legal Team Lead");
console.log(managerAlice.directReports);

// salary ok
console.log(charile.getSalary());
console.log(managerAlice.getSalary());
